package com.excel;

import java.util.ArrayList;
import java.util.List;



/**
 * 在表头初始化的过程中，也就决定了列的显示顺序
 * 
 * @author mike
 */
public class StringMergedColumns extends MergedColumns{
   
    private String formatStr;
    public StringMergedColumns(String formatStr) {
	this.formatStr = formatStr;
	
    }
    /**
     * 通过字符串格式合并列
     * 
     * @param formatNames
     *                格式为：mergedName(columnDisplay1:columnField1,columnDisplay2:columnField2);mergedName(columnDisplay1:columnField1,columnDisplay2:columnField2)
     */
    public List<ExcelColumn> mergeColumn() {
	String[] items = formatStr.split(Constant.SPLIT_FLAG_OUTER);
	for (int i = 0; i < items.length; i++) {
	    String item = items[i];
	    ExcelColumn excelColumn = null;
	    if (item.indexOf(Constant.SPLIT_FLAG) > 0) {
		excelColumn = new ComplexColumn();
		excelColumn.setComplex(true);
		excelColumn.mergeColumn(items[i]);
	    } else {
		excelColumn = new SimpleExcelColumn();
		excelColumn.setComplex(false);
		excelColumn.mergeColumn(items[i]);
	    }
	    list.add(excelColumn);
	    addField(excelColumn);
	}
	return list;
    }

  
    

}
